﻿using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using ZilLion.Service.WeChatMall.Domain.Repositorys.Interface.CrmProxy;
using ZilLion.Service.WeChatMall.Domain.Responses.CrmProxy;

namespace ZilLion.Service.WeChatMall.Controllers.CrmProxy
{
    /// <summary>
    ///     微信CRM 代理 -->客户信息
    /// </summary>
    [Route("Api/CrmProxy")]
    public class CrmCustController : WechatMallControllerBase
    {
        private readonly ICrmProxyRepository _crmProxyRepository;

        public CrmCustController(ICrmProxyRepository crmProxyRepository)
        {
            _crmProxyRepository = crmProxyRepository;
        }

        /// <summary>
        ///     获取微信交易流水
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
    
        [HttpGet("Cust/GetAccInfo")]
        public AccWalletSingleResponse GetAccInfo(string token = null)
        {
            return _crmProxyRepository.GetAccInfo(GetPassport(), GetCrmApiGetWay(), PassportType.WeChatAppidAndOpenid);
        }

        /// <summary>
        ///     获取微信卡交易流水
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet("GetTransactionFlowing")]
        public TransactionFlowingResponse GetTransactionFlowing(string token = null)
        {
            var respose = _crmProxyRepository.GetTransactionFlowing(GetPassport(), GetCrmApiGetWay(),
                PassportType.WeChatAppidAndOpenid);
            return respose != null
                ? new TransactionFlowingResponse
                {
                    TransactionFlowingList = respose.OprInfo.Where(x => x.Oprtype > 1).ToList()
                }
                : new TransactionFlowingResponse {TransactionFlowingList = new List<Oprinfo>()};
        }
    }
}